package com.itlxd.interceptor;

import com.itlxd.global.SysConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: lixiaodong
 **/
@Component
@Slf4j
public class UserLoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute(SysConstants.LOGIN_USER);

        if (null == loginUser){
            log.info("跳转到用户前台登陆");
            response.sendRedirect(SysConstants.USER_LOGIN_HTML);
        }
        log.info("返回true");
        return true;
        //return null == loginUser ? false : true;
    }
}
